//
//  qianViewController.m
//  家范
//
//  Created by 吴军虎吴军虎 on 16/4/13.
//  Copyright © 2016年 lanjue. All rights reserved.
//

#import "qianViewController.h"
#import "ChongViewController.h"
#import "LingViewController.h"
#import "LewPopupViewAnimationSpring.h"

@interface qianViewController ()<UITableViewDataSource,UITableViewDelegate>
{
    
    UITableView *tableView;
    UIView *headerView;
    UILabel *yuanlabel;
    UIButton *problemButton;
    UILabel *lineLabel;
    
}
@property (nonatomic,retain) UIView *myheaderView;


@end

@implementation qianViewController

-(void) viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBarHidden=YES;
    self.tabBarController.tabBar.hidden=YES;
    
}

-(void) viewWillDisappear:(BOOL)animated
{
    self.navigationController.navigationBarHidden=NO;
    self.tabBarController.tabBar.hidden=NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor=LV;
    
    
    [self createHeader];
}

#pragma mark 顶部

-(void) createHeader{
    //    //背景图
    _myheaderView=[[UIView alloc]init];
    _myheaderView.backgroundColor=GH;
    [self.view addSubview:_myheaderView];
    [_myheaderView mas_makeConstraints:^(MASConstraintMaker *make){
        
        make.top.equalTo(self.view).offset(0);
        make.size.mas_equalTo(CGSizeMake(self.view.frame.size.width, 64*AUTO_HEIGHT));
    }];
    //按钮
    UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:[UIImage imageNamed:@"fahui"] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    [_myheaderView addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make){
        
        make.top.equalTo(_myheaderView).offset(51/2 *AUTO_HEIGHT);
        make.left.equalTo(self.view).offset(20/2 *AUTO_WIDTH);
        make.size.mas_equalTo(CGSizeMake(34 *AUTO_WIDTH, 34 *AUTO_HEIGHT));
        
    }];
    //零钱
    UILabel *linglabel=[[UILabel alloc]init];
    linglabel.text=@"零钱";
    linglabel.textColor=[UIColor whiteColor];
    linglabel.adjustsFontSizeToFitWidth=YES;
    linglabel.textAlignment=NSTextAlignmentCenter;
    linglabel.font=[UIFont systemFontOfSize:ONETEXTWIDTH];
    [_myheaderView addSubview:linglabel];
    [linglabel mas_makeConstraints:^(MASConstraintMaker *make){
        
        make.top.equalTo(_myheaderView).offset(66/2 *AUTO_HEIGHT);
        make.left.equalTo(_myheaderView).offset((self.view.frame.size.width-100 *AUTO_WIDTH)/2);
        make.size.mas_equalTo(CGSizeMake(100*AUTO_WIDTH, 20 *AUTO_HEIGHT));
        
    }];
    
    
    //零钱明细
    UILabel *qianlabel=[[UILabel alloc]init];
    qianlabel.text=@"零钱明细";
    qianlabel.textColor=[UIColor whiteColor];
    qianlabel.font=[UIFont systemFontOfSize:16];
    qianlabel.textAlignment=NSTextAlignmentRight;
    qianlabel.userInteractionEnabled=YES;
    UITapGestureRecognizer *qiantap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(qantap:)];
    [qianlabel addGestureRecognizer:qiantap];
    [_myheaderView addSubview:qianlabel];
    [qianlabel mas_makeConstraints:^(MASConstraintMaker *make){
        
        make.top.equalTo(_myheaderView.mas_top).offset(66/2 *AUTO_HEIGHT);
        make.right.equalTo(self.view).offset(-30/2 *AUTO_WIDTH);
        make.size.mas_equalTo(CGSizeMake(80 *AUTO_WIDTH,20 *AUTO_HEIGHT));
    }];
    
    tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64.00*AUTO_HEIGHT, KScreenWidth, KScreenHeight - 64.00*AUTO_HEIGHT) style:UITableViewStyleGrouped];
    [self.view addSubview:tableView];
    tableView.separatorStyle = NO;
    tableView.backgroundColor = [UIColor whiteColor];
    tableView.dataSource = self;
    tableView.delegate = self;
    headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenHeight, 200.00*AUTO_HEIGHT)];
    headerView.backgroundColor = GH;
    
    tableView.tableHeaderView = headerView;
    [self addButton];
    [self addProblem];
    
    
}


//常见问题
-(void)addProblem{
    
    problemButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [tableView addSubview:problemButton];
    [problemButton setTitle:@"常见问题" forState:UIControlStateNormal];
    problemButton.titleLabel.font=[UIFont systemFontOfSize:14.00*AUTO_HEIGHT];
    [problemButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [problemButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        
        make.bottom.equalTo(tableView).offset(KScreenHeight - 80);
        make.size.mas_equalTo(CGSizeMake(KScreenWidth, 20));
        
    }];
    
}

-(void)addButton{
    
    //图片
    UIImageView *image=[[UIImageView alloc]init];
    image.image=[UIImage imageNamed:@"find_RMB"];
    [headerView addSubview:image];
    [image mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(headerView.mas_top).offset(36 *AUTO_HEIGHT);
        make.left.equalTo(self.view).offset(230/2 *AUTO_WIDTH);
        make.size.mas_equalTo(CGSizeMake(18 *AUTO_WIDTH, 18*AUTO_HEIGHT));
    }];
    
    //0.10
    yuanlabel=[[UILabel alloc]init];
    yuanlabel.text=@"0.10";
    yuanlabel.textColor=[UIColor whiteColor];
    yuanlabel.font=[UIFont fontWithName:SHUZI size:45];
    yuanlabel.textAlignment=NSTextAlignmentCenter;
    [headerView addSubview:yuanlabel];
    [yuanlabel mas_makeConstraints:^(MASConstraintMaker *make){
        
        make.top.equalTo(headerView.mas_top).offset(30 *AUTO_HEIGHT);
        make.left.equalTo(image).offset(10 *AUTO_WIDTH);
        make.size.mas_equalTo(CGSizeMake(100 *AUTO_WIDTH, 35 *AUTO_HEIGHT));
    }];
    
    
    //余额
    UILabel *yulabel=[[UILabel alloc]init];
    yulabel.text=@"余额（元）";
    yulabel.textColor=[UIColor whiteColor];
    yulabel.font=[UIFont systemFontOfSize:15];
    [headerView addSubview:yulabel];
    [yulabel mas_makeConstraints:^(MASConstraintMaker *make){
        
        make.top.equalTo(yuanlabel.mas_bottom).offset(10/2 *AUTO_HEIGHT);
        make.left.equalTo(self.view).offset(285/2 *AUTO_WIDTH);
        make.size.mas_equalTo(CGSizeMake(90 *AUTO_WIDTH, 20 *AUTO_HEIGHT));
    }];
    
    //横线
    UILabel *henglabel=[[UILabel alloc]init];
    henglabel.backgroundColor=[UIColor grayColor];
    henglabel.alpha=0.2;
    henglabel.layer.shadowOffset=CGSizeMake(0.8f, 1.0f);
    henglabel.layer.shadowOpacity=1.0f;
    [headerView addSubview:henglabel];
    [henglabel mas_makeConstraints:^(MASConstraintMaker *make){
        
        make.bottom.equalTo(headerView.mas_bottom).offset(-34 *AUTO_HEIGHT);
        make.left.equalTo(self.view).offset(0);
        make.size.mas_equalTo(CGSizeMake(self.view.frame.size.width, 1*AUTO_HEIGHT));
    }];
    
    //竖线
    UILabel *shulabel=[[UILabel alloc]init];
    shulabel.backgroundColor=[UIColor whiteColor];
    shulabel.alpha=0.6;
    [headerView addSubview:shulabel];
    [shulabel mas_makeConstraints:^(MASConstraintMaker *make){
        
        make.top.equalTo(henglabel.mas_bottom).offset(10/2 *AUTO_HEIGHT);
        make.left.equalTo(self.view).offset(self.view.frame.size.width/2);
        make.size.mas_equalTo(CGSizeMake(1 *AUTO_WIDTH, 25 *AUTO_HEIGHT));
    }];
    
    
    //充值按钮
    UIButton *chongbtn=[UIButton buttonWithType: UIButtonTypeCustom];
    chongbtn.tag = 1000;
    [chongbtn setTitle:@"充值" forState:UIControlStateNormal];
    [chongbtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    chongbtn.titleLabel.font=[UIFont systemFontOfSize:16];
    [chongbtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [headerView addSubview:chongbtn];
    [chongbtn mas_makeConstraints:^(MASConstraintMaker *make){
        
        make.top.equalTo(henglabel.mas_bottom).offset(0);
        make.left.equalTo(self.view).offset(0);
        make.size.mas_equalTo(CGSizeMake(self.view.frame.size.width/2, 64/2 *AUTO_HEIGHT));
    }];
    
    
    //充值图片
    UIImageView *chongimage=[[UIImageView alloc]init];
    chongimage.image=[UIImage imageNamed:@"yuan"];
    [headerView addSubview:chongimage];
    [chongimage mas_makeConstraints:^(MASConstraintMaker *make){
        
        make.top.equalTo(chongbtn.mas_top).offset(10/2 *AUTO_HEIGHT);
        make.left.equalTo(self.view).offset(95/2 *AUTO_WIDTH);
        make.size.mas_equalTo(CGSizeMake(22 *AUTO_WIDTH, 22 *AUTO_HEIGHT));
    }];
    
    
    //提现按钮
    UIButton *tibtn=[UIButton buttonWithType:UIButtonTypeCustom];
    tibtn.tag = 2000;
    [tibtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [tibtn setTitle:@"提现" forState:UIControlStateNormal];
    [tibtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    tibtn.titleLabel.font=[UIFont systemFontOfSize:15];
    [headerView addSubview:tibtn];
    [tibtn mas_makeConstraints:^(MASConstraintMaker *make){
        
        make.top.equalTo(henglabel.mas_bottom).offset(0);
        make.right.equalTo(self.view).offset(0);
        make.size.mas_equalTo(CGSizeMake(self.view.frame.size.width/2, 64/2 *AUTO_HEIGHT));
        
    }];
    
    
    //提现图片
    UIImageView *timage=[[UIImageView alloc]init];
    timage.image=[UIImage imageNamed:@"yuan1"];
    [headerView addSubview:timage];
    [timage mas_makeConstraints:^(MASConstraintMaker *make){
        
        make.top.equalTo(tibtn.mas_top).offset(10/2 *AUTO_HEIGHT);
        make.left.equalTo(shulabel).offset(95/2 *AUTO_WIDTH);
        make.size.mas_equalTo(CGSizeMake(22 *AUTO_WIDTH, 22 *AUTO_HEIGHT));
    }];
    
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableVie
{
    
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return 3;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellWithIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellWithIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellWithIdentifier];
    }
    cell.backgroundColor = [UIColor whiteColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    NSLog(@"indexPath==%@",indexPath);
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 0.1;
}


//充值
-(void) btnClick:(UIButton *) btn
{
    if (btn.tag == 1000) {
        ChongViewController *chong=[[ChongViewController alloc]init];
        [self.navigationController pushViewController:chong animated:YES];
    }
    
    else if(btn.tag == 2000) {
        if (yuanlabel.text.intValue <= 99) {
            NSLog(@"不够");
            UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 50)];
            label.backgroundColor = GH;
            label.font = [UIFont systemFontOfSize:14];
            label.alpha = 0.7;
            label.layer.masksToBounds = YES;
            label.layer.cornerRadius = 15;
            label.textColor = [UIColor whiteColor];
            label.text = @"余额不充足100元无法提现";
            label.textAlignment = NSTextAlignmentCenter;
            //自动折行设置
            label.lineBreakMode = UILineBreakModeWordWrap;
            label.numberOfLines = 0;
            
            [self lew_presentPopupView:label animation:[LewPopupViewAnimationSpring new] dismissed:^{
                
            }];
            
        }
        
        
    }
}
//
//零钱明细
-(void) qantap:(UITapGestureRecognizer *) tap
{
    LingViewController *ling=[[LingViewController alloc]init];
    [self.navigationController pushViewController:ling animated:YES];
}

//返回按钮
-(void) btnAction:(UIButton *) btn
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}


@end
